package cn.itsource.service.impl;

import cn.itsource.pojo.bo.WaitingFeeCalResult;
import cn.itsource.pojo.domain.ChargeRuleWait;
import cn.itsource.mapper.ChargeRuleWaitMapper;
import cn.itsource.service.IChargeRuleWaitService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 等待费用 服务实现类
 * </p>
 *
 * @author ????
 * @since 2024-06-29
 */
@Service
public class ChargeRuleWaitServiceImpl extends ServiceImpl<ChargeRuleWaitMapper, ChargeRuleWait> implements IChargeRuleWaitService {

    @Override
    public WaitingFeeCalResult cal(int min) {
        List<ChargeRuleWait> list = super.list();
        if (list.isEmpty())return new WaitingFeeCalResult();

        WaitingFeeCalResult result = new WaitingFeeCalResult();
        ChargeRuleWait chargeRuleWait = list.get(0);
        BigDecimal waitAmount = BigDecimal.ZERO;
        //大于免费分钟数
        if(min > chargeRuleWait.getFreeBaseWaitingMinute()){
            //超出免费部分的时间
            Integer moreMin = min - chargeRuleWait.getFreeBaseWaitingMinute();
            //超了多少分钟
            result.setExeceedBaseWaitingMinute(moreMin);

            //费用
            waitAmount = new BigDecimal(moreMin).multiply(chargeRuleWait.getExceedEveryMinuteAmount());
        }

        //免费分钟数
        result.setFreeBaseWaitingMinute(chargeRuleWait.getFreeBaseWaitingMinute());
        //每分钟价格
        result.setExeceedBaseWaitingEveryKmAmount(chargeRuleWait.getExceedEveryMinuteAmount());
        //等时费
        result.setWaitingAmount(waitAmount);

        return result;
    }
}
